package com.situ.mall.controller.front;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.entity.Result;
import com.situ.mall.entity.User;
import com.situ.mall.service.IUserService;

@Controller
@RequestMapping("/user")
public class FrontUserController {
	@Autowired
	private IUserService userService;

	@RequestMapping("/login.shtml")
	@ResponseBody
	public Result login(String username, String password, HttpSession session) {
		User user = userService.login(username, password);
		if (user == null) {
			return Result.error("登录失败");
		} else {
			// 登录成功后要将user放到Session
			session.setAttribute("user", user);
			return Result.success("登录成功");
		}
	}
}
